// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, Image, TouchableOpacity, ImageBackground, ScrollView, TextInput,InteractionManager } from 'react-native';

// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';
import ScrollableTabView from 'react-native-scrollable-tab-view';

// antd 按需加载
import { InputItem, Tabs, Toast, Portal, List, Picker } from '@ant-design/react-native';

// 引入 处理数据 所需文件
import { invoiceEdit, invoiceDel, invoiceGet } from '../../module/module.js'

// 引入样式
import Style from './style/style.js';

// 引入公用组件
import { Status, NavBar, ScrollableTabBar, Radio, InvoicesForm } from '../../components/index.js'

// 引入专用组件
import { } from './components'

// 引入工具包
import { press, size, ScreenWidth, borderBottom, hotTextColor, validation , defaultDataList,onEndReached,onRefresh ,concatDataList,defaultPage} from '../../util/utils.js'

class EditInvoice extends Component {

  constructor(props) {
    super(props)
    this.state = {
      details: {
        provinceId: '',
        provinceName: '',
        cityId: '',
        cityName: '',
        areaId: '',
        areaName: '',
        townId: '',
        townName: '',
        isDefault: false
      }
    }
  }


  componentDidMount() {
    const { id } = this.props
    this.loading = Toast.loading('加载中', 0)
    invoiceGet({ id }).then(res => {
      Portal.remove(this.loading)
      this.setState({
        details: res.data
      })
    }).finally(() => {
      Portal.remove(this.loading)
    })
  }

  invoiceEdit(option) {
    const { id } = this.props
    invoiceEdit({
      id,
      ...option
    }).then(res => {
      Toast.success(res.message, 1, () => {
        Actions.pop()
        Actions.refresh({})
      })
    })
  }

  invoiceDel() {
    const { id } = this.props
    invoiceDel({
      id,
    }).then(res => {
      Toast.success(res.message, 1)
    })
  }


  render() {
    const { details } = this.state
    return (
      <View style={Style.container}>
        <Status />
        <NavBar
          title="修改发票信息"
          back={true}
          extra="删除"
          extraOnPress={() => {
            this.invoiceDel()
          }}
        />
        <InvoicesForm details={details} onPress={(option) => this.invoiceEdit(option)}>修改发票信息</InvoicesForm>
      </View >
    );
  }
}

export default connect(({ user }) => ({
  user,
}))(pureRender(EditInvoice))
